//
//  QXMainTabBar.swift
//  QXWeibo
//
//  Created by QinXin on 15/6/23.
//  Copyright © 2015年 labi3285_Lab. All rights reserved.
//

import UIKit

class QXMainTabBar: UITabBar {
    
    private let btnCount = 5;
    
    
    lazy var compoesBtn: UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)

            self.addSubview(btn)
        return btn
    }()

    override func layoutSubviews() {
        super.layoutSubviews()
        
        let w = bounds.width / CGFloat(btnCount)
        let h = bounds.height
        
        var idx = 0
        for v in subviews {
            if v is UIControl && !(v is UIButton) {
                v.frame = CGRectMake(w * CGFloat(idx), 0, w, h)
                idx += idx == 1 ? 2 : 1
            }
        }
        
        compoesBtn.frame = CGRectMake(2 * w, 0, w, h)
        
    }

}
